package com.cleargroup.magic.cleara.c.command;

import android.content.Context;
import android.os.Environment;

import com.cleargroup.magic.cleara.c.BatteryHelper;

import java.io.File;
import java.util.List;


public class QuickTrashCommand extends ExaminableCommand {
	public static final String TAG = QuickTrashCommand.class.getSimpleName();

	private static String sdcard = Environment.getExternalStorageDirectory()
			.toString();
	private static String path1 = sdcard + "/DCIM/.thumbnails";
	private static String path2 = sdcard + "/LOST.DIR";
	//	private static String path3 = sdcard + "/Android";

	private long total_amount;
	private long total_size;

	private Scan scan;

	public QuickTrashCommand(Context context) {
		super(context);
	}

	public void examine() {
		total_size = 0;
		total_amount = 0;

		scan = new Scan(getContext());
		scan.setListener(new ScanListener() {
			public void onNodeScan(File node) {
				int type = TrashHelper.detect(node);
				if (type != TrashHelper.TRASH_NORMAL) {
					total_size += node.length();
					total_amount++;
				}
			}
		});
		scan.bfs(path1);
		scan.bfs(path2);
		//		scan.bfs(path3, false);

		onExamined(getContext(), total_amount, total_size);
	}

	public void execute(List... lists) {
		if (lists.length == 0) {
			total_size = 0;

			scan = new Scan(getContext());
			scan.setListener(new ScanListener() {
				public void onNodeScan(File node) {
					int type = TrashHelper.detect(node);
					if (type != TrashHelper.TRASH_NORMAL) {
						total_size += node.length();
						total_amount++;
						BatteryHelper.delete(node);
					}
				}
			});
			scan.bfs(path1);
			scan.bfs(path2);

			onExecuted(getContext(), -1, total_size);
		}
	}

}
